package com.zjy.system.controller;

import com.zjy.basic.util.AjaxResult;
import com.zjy.basic.util.PageList;
import com.zjy.system.domain.Systemdictionarydetail;
import com.zjy.system.query.SystemdictionarydetailQuery;
import com.zjy.system.service.SystemdictionarydetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {

    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailService.findAll();
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id") Long id){
        return systemdictionarydetailService.findById(id);
    }

    /**
     * 查询多个
     * @param id
     * @return
     */
    @GetMapping("/type/{id}")
    public List<Systemdictionarydetail> findByTypesId(@PathVariable("id") Long id){
        return systemdictionarydetailService.findByTypesId(id);
    }


    /**
     * 接口：分页查询
     * @param systemdictionarydetailQuery
     * @return
     */
    //post http://localhost:8080/systemdictionarydetail 对象
    @PostMapping
    @ApiOperation(value = "分页查询" )
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return systemdictionarydetailService.queryPage(systemdictionarydetailQuery);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.del(id);
            return new AjaxResult(true,"删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    public AjaxResult save(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if(systemdictionarydetail.getId()==null){
                systemdictionarydetailService.add(systemdictionarydetail);
            }else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult(true,"操作成功");
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            systemdictionarydetailService.patchDel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

}
